from Interface.wechat_po.apis.base_api import BaseApi


class WeWork(BaseApi):

    # def __init__(self,corpid, secret):
    #     self.access_token = self.get_token(corpid, secret)

    def __init__(self):
        self.access_token = None

    def get_token(self, corpid, secret):
        """
        获取token
        :return:
        """
        # 定义 corpid 和 contact_secret
        # corpid = "wwe64fcf5a2b01b901"
        # corpsecret = "XXagezH8lR0R4H0XebwzWWEJ8o7lpjXaxkxj1mE_K0I"
        # 定义url
        url = "/gettoken"
        # 定义使用参数
        params = {
            "corpid": corpid,
            "corpsecret": secret
        }
        # 发起接口请求
        req = {
            "method": "GET",
            "url": url,
            "params": params
        }
        # r = Interface.request("GET", url=url, params=params)
        r = self.send_api(req)
        # 提取token
        # token = r.json().get("access_token")
        self.access_token = r.json().get("access_token")
        # 返回token
        # return token
